package cn.wetcland.urban.framework.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.wetcland.urban.common.utils.CopyObjectUtil;
import cn.wetcland.urban.framework.dto.CustomerAppealDTO;
import cn.wetcland.urban.framework.mapper.UtAppealMapper;
import cn.wetcland.urban.framework.service.UtAppealService;
import cn.wetcland.urban.framework.utils.StpDriverUtil;
import cn.wetcland.urban.generator.domain.UtAppeal;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Wetcland
* @description 针对表【ut_appeal】的数据库操作Service实现
* @createDate 2024-01-21 09:51:59
*/
@Service
public class UtAppealServiceImpl extends ServiceImpl<UtAppealMapper, UtAppeal> implements UtAppealService {

    @Resource
    public UtAppealMapper appealMapper;

    @Override
    public void handleCustomerAppeal(CustomerAppealDTO appealDTO) {
        long loginIdAsLong = StpUtil.getLoginIdAsLong();
        UtAppeal utAppeal = new UtAppeal();
        utAppeal.setCustomerId(loginIdAsLong);
        utAppeal.setAppealRole(1);
        CopyObjectUtil.copyPropertiesIgnoreNull(appealDTO, utAppeal);
        appealMapper.insert(utAppeal);
    }

    @Override
    public void handleDriverAppeal(CustomerAppealDTO appealDTO) {
        long loginIdAsLong = StpDriverUtil.getLoginIdAsLong();
        UtAppeal utAppeal = new UtAppeal();
        utAppeal.setDriverId(loginIdAsLong);
        utAppeal.setAppealRole(2);
        CopyObjectUtil.copyPropertiesIgnoreNull(appealDTO, utAppeal);
        appealMapper.insert(utAppeal);
    }

    @Override
    public List<UtAppeal> customerAppealList(Integer status) {
        long loginIdAsLong = StpUtil.getLoginIdAsLong();
        return appealMapper.selectList(new QueryWrapper<UtAppeal>()
                .eq("appeal_role", 1)
                .eq("customer_id", loginIdAsLong)
                .eq("appeal_status", status)
        );
    }

    @Override
    public List<UtAppeal> driverAppealList(Integer status) {
        long loginIdAsLong = StpDriverUtil.getLoginIdAsLong();
        return appealMapper.selectList(new QueryWrapper<UtAppeal>()
                .eq("appeal_role", 2)
                .eq("customer_id", loginIdAsLong)
                .eq("appeal_status", status)
        );
    }
}




